# -*- coding: utf-8 -*-
import scrapy
from maoyan.items import MaoyanfilmItem

class MaoyanfilmsSpider(scrapy.Spider):
    name = 'maoyanfilms'
    allowed_domains = ['maoyan.com']
    start_urls = ['https://maoyan.com/board/4']

    def parse(self, response):
        movie_items = response.xpath('//*[@id="app"]/div/div/div[1]/dl/dd')
        print(len(movie_items))
        for item in movie_items:
            # print(len(item))
            movie = MaoyanfilmItem()
            movie['filmnames'] = item.xpath(' div / div / div[1] / p[1] / a/text()').extract()[0]
            print(movie['filmnames'])
            movie['filmdate'] = item.xpath('div/div/div[1]/p[3]/text()').extract()[0].split(':')
            moviescorem = item.xpath('div/div/div[2]/p/i[1]/text()').extract()
            moviescoren = item.xpath('div/div/div[2]/p/i[2]/text()').extract()
            movie['filmscore'] = moviescorem[0] + moviescoren[0]
            yield movie
        pass
